﻿#include <iostream>
#include <vector>
#include <map>
using namespace std;

class SunnyShip
{
private:
  vector<string> m_parts;

public:
  void addParts(const string &part)
  {
    m_parts.push_back(part);
  }
  void showParts()
  {
    for (const string &part : m_parts)
    {
      cout << part << " ";
    }
    cout << endl;
  }
};
class MerryShip
{
private:
  map<string, string> m_parts;

public:
  void assemble(const string &name, const string &parts)
  {
    m_parts.insert(make_pair(name, parts));
  }
  void showParts()
  {
    for (const auto &part : m_parts)
    {
      cout << part.first << ": " << part.second << "\n";
    }
    cout << endl;
  }
};
class AbShipBuider
{
public:
  virtual void buildBody() = 0;
  virtual void buildWeapon() = 0;
  virtual void buildEigen() = 0;
  virtual void buildInteriro() = 0;
};
class SunnyBuilder : public AbShipBuider
{
private:
  SunnyShip *sunny_ship;

public:
  SunnyBuilder()
  {
    sunny_ship = new SunnyShip;
  }
  void buildBody() override
  {
    sunny_ship->addParts("Sunny特制船体");
  }
  void buildWeapon() override
  {
    sunny_ship->addParts("Sunny特制武器");
  }
  void buildInteriro() override
  {
    sunny_ship->addParts("Sunny特制内室");
  }
  void buildEigen()
  {
    sunny_ship->addParts("Sunny特制引擎");
  }
  SunnyShip *getShip()
  {
    return this->sunny_ship;
  }
};
class MerryBuilder : public AbShipBuider
{
private:
  MerryShip *merry_ship;

public:
  MerryBuilder()
  {
    merry_ship = new MerryShip;
  }
  void buildBody() override
  {
    merry_ship->assemble("船体", "Merry特制船体");
  }
  void buildWeapon() override
  {
    merry_ship->assemble("武器", "Merry特制武器");
  }
  void buildInteriro() override
  {
    merry_ship->assemble("内室", "Merry特制内室");
  }
  void buildEigen() override
  {
    merry_ship->assemble("引擎", "Merry特制引擎");
  }
  MerryShip *getShip()
  {
    return this->merry_ship;
  }
};
class Director
{
private:
  AbShipBuider *m_builder;

public:
  Director()
  {
    m_builder = nullptr;
  }
  void setBuilder(AbShipBuider *builder)
  {
    m_builder = builder;
  }
  void buildSimpleShip()
  {
    m_builder->buildBody();
    m_builder->buildEigen();
  }
  void buildStandardShip()
  {
    buildSimpleShip();
    m_builder->buildWeapon();
  }
  void buildRegalShip()
  {
    buildStandardShip();
    m_builder->buildInteriro();
  }
};
int main()
{
  // 建造三种型号的Sunny号船
  Director director;
  MerryBuilder *builder_sunny = new MerryBuilder;
  // step01：简易类型
  director.setBuilder(builder_sunny);
  director.buildSimpleShip();
  MerryShip *merry_ship = builder_sunny->getShip();
  merry_ship->showParts();
  delete merry_ship;
  merry_ship = 0;
  delete builder_sunny;
  builder_sunny = 0;
  // step02:标准类型
  cout << "***********************************************" << endl;
  builder_sunny = new MerryBuilder;
  director.setBuilder(builder_sunny);
  director.buildStandardShip();
  merry_ship = builder_sunny->getShip();
  merry_ship->showParts();
  delete merry_ship;
  merry_ship = 0;
  delete builder_sunny;
  builder_sunny = 0;
  // step03:旗舰型号
  cout << "***********************************************" << endl;
  builder_sunny = new MerryBuilder;
  director.setBuilder(builder_sunny);
  director.buildRegalShip();
  merry_ship = builder_sunny->getShip();
  merry_ship->showParts();
  delete builder_sunny;
  builder_sunny = 0;
  delete merry_ship;
  merry_ship = 0;

  return 0;
}
